import baseUrl from "./baseUrl.js";
import request from "@/utils/http.request.js";

const permission = {
    /**
     * 获取权限分页
     * @param pageIndex
     * @param pageSize
     * @param keyword 关键字
     * @param _response 
     * @param _finally 
     * @returns {*|void}
     */
    pageList(pageIndex, pageSize, keyword, _response, _finally = null) {
        return request.get(`${baseUrl.permission}/pagelist`, { pageIndex: pageIndex, pageSize: pageSize, keyword: keyword }, _response, _finally);
    },
    /**
    * 添加权限         
    * @param permissionName 权限名称
    * @param permissionCode 权限代码
    * @param url url
    * @param icon 图标
    * @param order 排序号
    * @param type 权限类型
    * @param parentId 父级Id
    * @param _response 
    * @param _finally 
    * @returns 
    */
    add(permissionName, permissionCode, url, icon, order, type, parentId, _response, _finally = null) {
        return request.postWithJson(`${baseUrl.permission}`, { permissionName: permissionName, permissionCode: permissionCode, url: url, icon: icon, order: order, type: type, parentId: parentId }, _response, _finally);
    },
    /**
     * 修改权限
     * @param permissionId 权限Id
     * @param permissionName 权限名称
     * @param permissionCode 权限代码
     * @param url url
     * @param icon 图标
     * @param order 排序号
     * @param type 权限类型
     * @param parentId 父级Id
     * @param _response 
     * @param _finally 
     * @returns 
     */
    edit(permissionId, permissionName, permissionCode, url, icon, order, type, parentId, _response, _finally = null) {
        return request.putWithJson(`${baseUrl.permission}`, { permissionId: permissionId, permissionName: permissionName, permissionCode: permissionCode, url: url, icon: icon, order: order, type: type, parentId: parentId }, _response, _finally);
    },
    /**
     * 删除权限
     * @param permissionId 权限id
     * @param _response 
     * @param _finally 
     * @returns 
     */
    delete(permissionId, _response, _finally = null) {
        return request.deleteWithouParam(`${baseUrl.permission}/${permissionId}`, _response, _finally)
    },
    /**
     * 根据类型获取权限树
     * @param {} type 
     * @param {*} _response 
     * @param {*} _finally 
     */
    tree(type, _response, _finally = null) {
        return request.getWithoutParam(`${baseUrl.permission}/tree/${type}`, _response, _finally);
    },
    /**
     * 根据类型获取自己的权限树
     * @param {} type 
     * @param {*} _response 
     * @param {*} _finally 
     */
    myTree(type, _response, _finally = null) {
        return request.getWithoutParam(`${baseUrl.permission}/mytree/${type}`, _response, _finally);
    }
};

export default permission;